<?php
ini_set('default_charset','utf-8');
include $_SERVER['DOCUMENT_ROOT'].'/lib/router.class.php';
include $_SERVER['DOCUMENT_ROOT'].'/conf/api_routs.php';
$router=ROUTER::inst();

$router->register('GET','counrty/{^\d+$}',false, 'geo.php/geo/get_country' );

if(!$s=$router->resolve('GET','counrty/654','id=JOHN')){
  echo json_encode( array('error'=>$router->get_errors()) );
	exit();
}
//echo '<pre class="debug">'.print_r ( $s ,true).'</pre>';exit();

$t=explode('/',$s->code);

$inc=$_SERVER['DOCUMENT_ROOT'].'/lib/'.$t[0];
if(!file_exists($inc)){
	echo 'include file not found'; exit();
}
include_once $inc;

if(!class_exists($t[1])){
  echo 'class not found'; exit();
}
$dynClass=new $t[1];

if(!method_exists($dynClass, $t[2])){
  echo 'method not found'; exit();
}
$data=call_user_func_array(array($dynClass,$t[2]), $s->params);
//echo '<pre class="debug">'.print_r ( $data ,true).'</pre>';
echo json_encode($data);
?>